﻿using System.Timers;
using System.Windows;
using System.Windows.Input;
using WangYiYunWPF.ViewModels;

namespace WangYiYunWPF
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public static MainWindow mainWindow { get; private set; }
        public MainWindow()
        {
            mainWindow = this;
            InitializeComponent();
            var model = MainWindowViewModel.GetInstance();
            DataContext = model;
        }

        private void headWindow_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (e.ButtonState == MouseButtonState.Pressed) {
                MainWindow.mainWindow.DragMove();
            }
            //双击事件放大缩小
            var element = (FrameworkElement)sender;
            if (e.ClickCount == 1)
            {
                var timer = new System.Timers.Timer(500);
                timer.AutoReset = false;
                timer.Elapsed += new ElapsedEventHandler((o, ex) => element.Dispatcher.Invoke(new Action(() =>
                {
                    var timer2 = (System.Timers.Timer)element.Tag;
                    timer2.Stop();
                    timer2.Dispose();
                })));
                timer.Start();
                element.Tag = timer;
            }
            if (e.ClickCount > 1)
            {
                var timer = element.Tag as System.Timers.Timer;
                if (timer != null)
                {
                    timer.Stop();
                    timer.Dispose();
                    MainWindowViewModel.GetInstance().ZoomWindow();
                }
            }
        }
    }
}